package com.ylyq.ylxx.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ylyq.ylxx.entity.YlyqCity;
import com.ylyq.ylxx.entity.YlyqUser;
import com.ylyq.ylxx.model.ResponseData;
import com.ylyq.ylxx.model.bean.OceanenginePlanInfo;
import com.ylyq.ylxx.model.request.GetCityRequest;
import com.ylyq.ylxx.model.request.GetPlanInfoRequest;
import com.ylyq.ylxx.service.IYlyqCityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author xiaweichao
 * @since 2020-07-22
 */
@RestController
@RequestMapping("/city")
@Api(description = "获取城市的相关接口")
public class YlyqCityController {

    @Autowired
    private IYlyqCityService iYlyqCityService;

    @PostMapping("/getCity")
    @ApiOperation(value = "获取城市", response = OceanenginePlanInfo.class)
    public ResponseData getCity(@Valid @RequestBody GetCityRequest getCityRequest) {
        QueryWrapper<YlyqCity> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(getCityRequest.getCityName()))
            wrapper.eq("city_name", getCityRequest.getCityName());
        if(null!=getCityRequest.getCityFlag())
            wrapper.eq("city_flag", getCityRequest.getCityFlag());
        if(null!=getCityRequest.getCityId())
            wrapper.eq("city_id", getCityRequest.getCityId());

        List<YlyqCity> list = iYlyqCityService.list(wrapper);

        return new ResponseData(ResponseData.Result.SUCCESS,list);
    }
}
